#include "World.h"


World::World(GameObjectFactory* factory): objectFactory(factory)
{
}


World::~World()
{
	Clear();
}

void World::Clear()
{
	std::list<GameObject*>::iterator it;


	for(it = objects.begin(); it != objects.end(); ++it)
	{
		delete (*it);
	}

	objects.clear();
}

void World::Resize(unsigned int width, unsigned int height)
{
	board.Resize(width, height);
}


void World::AddObject(GameObject* object, unsigned int cellX, unsigned int cellY)
{
	objects.push_back(object);

	board.Move(object, cellX, cellY);
}

GameObject* World::AddRobot(const std::string& type, unsigned int cellX, unsigned int cellY)
{
	GameObject* object = 0;


	if (objectFactory)
	{
		object = objectFactory->CreateRobot(type);

		AddObject(object, cellX, cellY);
	}

	return object;
}

void World::Move(GameObject* object, unsigned int cellX, unsigned int cellY)
{
	board.Move(object, cellX, cellY);
}

void World::Print()
{
	board.Print();
}

